XML::RSS Update: Refactoring

Shlomi Fish on 2007-02-02T14:25:58

After we got XML::RSS to a stage where it has 100% test coverage, it was possible to refactor things with more assurance that we don't break anything. So I did exactly that and gave XML::RSS a facelift.

Among the things I did were:

  1. Extracted many methods, including some that appeared several times.
  2. Instead of the $output .= "<tag>"... pattern, converted everything to append to a buffer that is stored in an object property, and using $self->_out($mystring) calls and many methods on top of it for outputting entire tags, and higher-level abstractions.
  3. Made sure all tags end with one newline and not two as was the case for some of them. This enabled an easier refactoring.
  4. Got rid of the AUTOLOAD method, which was only used for accessors, and instead wrote several such accessors manually using the _handle_accessor() method. This should eliminate many obscure errors in using XML::RSS and also make things somewhat faster.
  5. Converted many direct member retrievals (->{'channel'}...) to their accessor versions.
  6. Made many methods common to all RSS versions with the differences encapsulated in checks for the current _rss_out_version() object parameter, which is assigned at the beginning of the rendering process.
  7. Converted several if-elsif-else-constructs to dispatches.

Meanwhile, Ask ran perltidy on the "lib/XML/RSS.pm" module itself to make its style more consistent. (Which I may have broken somewhat since then, but since the perltidy configuration file is in the repository, we can run it again.) With all of these changes, the code looks much better, than it used to before I started working on it.

I still have some changes I'd like to make in the pipe, like converting each RSS output version into a class and using the convert conditional to polymorphism refactoring, and making the XML parsing functions accept the XML::RSS object handle as an argument, so we can use true methods there instead of just functions inside the same namespace. I'm still waiting for Ask to approve these changes as he didn't reply to my email about it yet.